#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int n , m;
priority_queue<int,vector<int>,greater<int>>q;
int main()
{
    cin >> n >> m;
    int ret = 0;
    for(int i = 1;i <= m;i ++) q.push(0);
    for(int i = 1;i <= n;i ++)
    {
        int x; cin >> x;
        int t = q.top(); q.pop();
        t += x;
        ret = max(ret , t);
        q.push(t);
    }
    cout << ret << endl;
    return 0;
}